<template>
	<view class="new_page ligth_page">
		<view class="main">
			<view class="search_wrap">
				<view class="search">
					<uni-search-bar class="uni-mt-0" radius="100" placeholder="请输入电话号" clearButton="auto" cancelButton="none"
						@confirm="search" />
				</view>
				<view class="ss">
					<uni-data-select :clear="false" v-model="value" :localdata="range" @change="change"></uni-data-select>
				</view>
			</view>

			<!-- tag -->
			<view class="tag_wrap">
				<view class="tag_item" v-for="(item,index) in tagList" :key="index" @click="activeIndex=index"
					:class="{'active':activeIndex==index}">
					<text>{{item}}</text>
				</view>
			</view>

			<!-- 表单 -->
			<view class="list_wrap">
				<swiper :indicator-dots="false" :autoplay="false" :interval="4000" :duration="500" @change="handleChange"
					:current="activeIndex" style="height: 100%">
					<!-- 全部 -->
					<view>
						<swiper-item style="overflow: auto">
							<view class="swiper-item">
								<view class="item_content">
									<view class="row title_wrap">
										<view class="title row_item" v-for="(title,i) in titleList" :key="i">
											<text>{{title}}</text>
										</view>
									</view>
									<!-- 门店 -->
									<view class="row" v-for="(order,i) in callList" :key="i">
										<view class="row_item no-wrap">
											{{order.userName}}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text @click="callPhone(order.userPhoneNumber)">{{order.userPhoneNumber}}</text>
											</view>
										</view>
										<view class="row_item" @click="activeIndex=1">
											门店电话
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.callTime}}</text>
										</view>
									</view>
									<!-- 咨询 -->
									<view class="row" v-for="(order,i) in saveList" :key="i">
										<view class="row_item no-wrap">
											{{order.nickName}}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text @click="callPhone(order.userPhoneNumber)">{{order.userPhoneNumber}}</text>
											</view>
										</view>
										<view class="row_item" @click="activeIndex=2">
											微信咨询
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.time}}</text>
										</view>
									</view>
									<!-- 预约 -->
									<view class="row" v-for="(order,i) in orderList" :key="i">
										<view class="row_item no-wrap">
											{{order.userName}}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text @click="callPhone(order.userPhoneNumber)">{{order.userPhoneNumber}}</text>
											</view>
										</view>
										<view class="row_item" @click="activeIndex=3">
											预约
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.orderTime}}</text>
										</view>
									</view>

								</view>
							</view>
						</swiper-item>
					</view>
					<!-- 门店电话 -->
					<view>
						<swiper-item style="overflow: auto">
							<view class="swiper-item">
								<view class="item_content">
									<view class="row title_wrap">
										<view class="title row_item" v-for="(title,i) in titleList" :key="i">
											<text>{{title}}</text>
										</view>
									</view>
									<view class="row" v-for="(order,i) in callList" :key="i">
										<view class="row_item no-wrap">
											{{order.userName}}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text @click="callPhone(order.userPhoneNumber)">{{order.userPhoneNumber}}</text>
											</view>
										</view>
										<view class="row_item">
											门店电话
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.callTime}}</text>
										</view>
									</view>
								</view>
							</view>
						</swiper-item>
					</view>
					<!-- 微信咨询 -->
					<view>
						<swiper-item style="overflow: auto">
							<view class="swiper-item">
								<view class="item_content">
									<view class="row title_wrap">
										<view class="title row_item" v-for="(title,i) in titleList" :key="i">
											<text>{{title}}</text>
										</view>
									</view>
									<view class="row" v-for="(order,i) in saveList" :key="i">
										<view class="row_item no-wrap">
											{{order.nickName}}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text @click="callPhone(order.userPhoneNumber)">{{order.userPhoneNumber}}</text>
											</view>
										</view>
										<view class="row_item">
											微信咨询
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.time}}</text>
										</view>
									</view>
								</view>
							</view>
						</swiper-item>
					</view>
					<!-- 预约 -->
					<view>
						<swiper-item style="overflow: auto">
							<view class="swiper-item">
								<view class="item_content">
									<view class="row title_wrap">
										<view class="title row_item" v-for="(title,i) in titleList" :key="i">
											<text>{{title}}</text>
										</view>
									</view>
									<view class="row" v-for="(order,i) in orderList" :key="i">
										<view class="row_item no-wrap">
											{{order.userName}}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text @click="callPhone(order.userPhoneNumber)">{{order.userPhoneNumber}}</text>
											</view>
										</view>
										<view class="row_item">
											预约
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.orderTime}}</text>
										</view>
									</view>
								</view>
							</view>
						</swiper-item>
					</view>
					<view>
						<swiper-item style="overflow: auto">
							<view class="swiper-item">
								<view class="item_content">
									<view class="row title_wrap">
										<view class="title row_item" v-for="(title,i) in paytitleList" :key="i">
											<text>{{title}}</text>
										</view>
									</view>
									<view class="row" v-for="(order,i) in payList" :key="i">
										<view class="row_item no-wrap">
											{{order.couponId }}
										</view>
										<view class="row_item">
											<view class="user_info">
												<text>{{order.eventName}}</text>
											</view>
										</view>
										<view class="row_item">
											{{order.orderStatus=='V'?'已核销':'未核销'}}
										</view>
										<view class="row_item">
											<text class="uni-primary">{{order.orderDateTime}}</text>
										</view>
									</view>
								</view>
							</view>
						</swiper-item>
					</view>
				</swiper>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getOrderLine,
		getorderpay,
		getcallhistory,
		getsaveQrCodeHistory
	} from '@/request/api.js'
	export default {
		data() {
			return {
				activeIndex: 0,
				tagList: [
					'全部',
					'门店电话',
					'咨询',
					'预约',
					'交易'
					// '线下录入'
				],
				titleList: [
					'用户名',
					'联系方式',
					'分类',
					'时间'
				],
				savetitleList: [
					'用户名',
					'联系方式',
					'康复中心',
					'操作'
				],
				paytitleList: [
					'订单号',
					'活动名称',
					'是否使用',
					'时间'
				],
				calltitleList: [
					'门店名称',
					'用户名',
					'电话'
				],
				orderList: [],
				payList: [],
				callList: [],
				saveList: [],
				value: 0,
				pages:{
					phone:'',
					types:''
				},
				range: [{
						value: 0,
						text: "近30天"
					},
					{
						value: 1,
						text: "近一年"
					},
					{
						value: 2,
						text: "近三年"
					},
					{
						value: 3,
						text: "全部"
					},
				],
			}
		},
		onLoad() {

		},
		mounted() {
			this.getOrderLine()
			this.getorderpay();
			this.getcallhistory();
			this.getsaveQrCodeHistory();
		},
		methods: {
			callPhone(e) {
				uni.makePhoneCall({
					phoneNumber: e, //仅为示例，并非真实的电话号码
					success: function() {
						console.log("拨打电话成功！")
					},
					fail: function() {
						console.log("拨打电话失败！")
					}
				})
			},
			change(e) {
				console.log("e:", e);
				this.pages.types = e
				//开始查询
				this.getOrderLine()
				this.getorderpay();
				this.getcallhistory();
				this.getsaveQrCodeHistory();
			},
			search(e) {
				let phone = e.value
				this.pages.phone = e.value
				this.getcallhistory()
				this.getOrderLine()
			},
			handleChange(e) {
				this.activeIndex = e.detail.current;
			},
			// 获取预约信息
			async getOrderLine() {
				let pages = this.pages
				let res = await getOrderLine({
					num: pages.phone,
					types:pages.types
				});
				this.orderList = res.data
			},
			async getorderpay() {
				let pages = this.pages
				let res = await getorderpay({
					num: pages.phone,
					types:pages.types
				});
				this.payList = res.data
			},
			async getcallhistory() {
				let pages = this.pages
				let res = await getcallhistory({
					num: pages.phone,
					types:pages.types
				});
				this.callList = res.data
			},
			async getsaveQrCodeHistory() {
				let pages = this.pages
				let res = await getsaveQrCodeHistory({
					num: pages.phone,
					types:pages.types
				});
				this.saveList = res.data
			},
		}
	}
</script>
<style lang="scss" scoped>
	.new_page {
		height: 100%;

		.main {
			display: flex;
			flex-direction: column;
			height: 100%;
		}
	}

	.search_wrap {
		background-color: #2C65BB;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 30rpx;
		box-sizing: border-box;

		.search {
			width: 60%;
		}
		.ss {
			width: 200rpx;
			background-color: #fff;
			border-radius: 6rpx;
		}
	}

	.tag_wrap {
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: sticky;
		top: 0;

		.tag_item {
			position: relative;
			font-size: 25rpx;
			color: $text-grey;
			padding: 6rpx 20rpx;
			margin: 30rpx 0;

			&.active {
				color: $uni-primary;
				font-size: 29rpx;

				&::after {
					content: "";
					position: absolute;
					left: 0;
					right: 0;
					bottom: -4rpx;
					margin: auto;
					width: 70%;
					height: 2px;
					background-color: $uni-primary;
				}
			}
		}
	}

	.list_wrap {
		flex: 1;

		.item_content {
			width: 95%;
			margin: auto;

			.title_wrap {
				background-color: #D8D8D8 !important;
				border-radius: 7rpx 7rpx 0 0;
				font-size: 25rpx;

				.row_item:nth-child(n+2) {
					border-left: 1px solid #C4C4C4;
				}
			}

			.row {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #e9e9e9;
			}

			.row:nth-child(2n) {
				background-color: #fff;
			}

			.row_item {
				flex: 1;
				padding: 20rpx 0;
				display: flex;
				justify-content: center;
				align-items: center;
				text-align: center;
				font-size: 22rpx;

				.user_info {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
				}

				.ml {
					margin-left: 10rpx;
				}
			}
		}
	}
</style>